﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;

namespace Trans.customer
{
    public partial class Add_customer : Form
    {
        public Add_customer()
        {
            InitializeComponent();
        }

        private void Add_customer_Load(object sender, EventArgs e)
        {
         
            tbcustomerBindingSource.AddNew();
            
        }

        private void bt_save_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                try
                {
                    tbcustomerBindingSource.EndEdit();
                    dataSet.tb_customer.Rows[0]["date"] = DateTime.Now;
                    tb_customerTableAdapter.Update(dataSet.tb_customer);
                    this.Hide();
                    MessageBox.Show("添加成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("出错啦" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            tbcustomerBindingSource.CancelEdit();
            this.Hide();
        }

        private void tx_userid_Validating(object sender, CancelEventArgs e)
        {
            if (
                ((int)tb_customerTableAdapter.ValidaUserid(tx_userid.Text) > 0)
                )
                   
            {
                error.SetError(tx_userid, "用户名重复");
                e.Cancel = true;
                return;

            }
            if(tx_userid.Text.Equals(""))
            {
                error.SetError(tx_userid, "缺少用户名");
                e.Cancel = true;
                return;

            }
                error.SetError(tx_userid, "");
        }

        private void tx_passwd_Validating(object sender, CancelEventArgs e)
        {
            if (tx_passwd.Text.Equals(""))
            {
                error.SetError(tx_passwd, "必填项!");
                e.Cancel=true;
            }
            else
                error.SetError(tx_passwd, "");
      
        }
    }
}
